Skip to content

Intersections: compute sweep fields bottom-up along the status for overlapping segments - #392

Closed
anaelorlinski wants to merge 1 commit into
tdewolff:masterfrom
anaelorlinski:fix/bo-overlapping-windings
Closed

anaelorlinski wants to merge 1 commit into
tdewolff:masterfrom
anaelorlinski:fix/bo-overlapping-windings

Conversation

@anaelorlinski

Copy link
Copy Markdown
Contributor

While reviewing my panic workarounds in canvas intersection (mainly workaround by adding perturbation at clip bounds) I made claude work ok the #382 issue because it was integrated in my fork.

Seems to be the fix for it but I don't have the proper knowledge to confirm.

…erlapping segments

The sweep fields of the left-endpoints in a tolerance square are computed
in CompareH order, each from the segment below it in the sweep status.
Windings propagate bottom-up along the status, so this is only correct
when the two orders agree. For overlapping segments that start in the same
point they need not: a segment can then read the windings of a neighbour
that has not been computed yet, gets zeros, and every segment above the
stack inherits the error. mergeOverlapping later recomputes the merged
stack itself, but not the segments above it, so the result polygon walk
arrives at a vertex on a boundary segment and finds no segment leaving
it: "next node for result polygon is nil" in debug mode, a silently
truncated contour otherwise.

Compute a left-endpoint's fields only after those of the segment below it
when that segment starts in the same point, and mark computed endpoints
so a segment is never computed twice. Split pieces start unmarked.

This is the failure behind tdewolff#382: the stroke outline of a merged grid of
nearly-exact cells, where the outlines of adjacent cells overlap exactly
along shared edges. The fixture from that PR now settles to the outer
square in debug mode. The regression test builds equivalent geometry from
a seeded grid with 1e-17 corner noise; four seeds panic before this
change and settle to a single square of area 1.44 after it.

Not addressed: some noisier grids hit "first segment became vertical and
needs reversal, but was already in the sweep status", which is a
different failure.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@tdewolff

tdewolff commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Was the fix wrong for both PRs?

@anaelorlinski

Copy link
Copy Markdown
Contributor Author

The 2 fixes improve the intersections computation but there are still other issues on the algorithm after applying them.
I made Claude work on it and it concludes that it will be quite hard to fix all of them due the usage of floating point computation. I will still prepare the 3rd commit that adds other fixes and place it in a branch so you can have a look.

In parallel I made Claude work on a different approach to use an algorithm that work with integers and the results are promising (better speed and accuracy) : Claude ported Clipper2 from Go to C++, made it work on fixing the issues found in the Github, ported test suites from various similar projects (iOverlay, polygon-clipping). You can have a look at the repo but there is still pending items and few items to investigate in canvas test suite (everything else passes).
https://github.com/anaelorlinski/clipper2-go/

@anaelorlinski
anaelorlinski deleted the fix/bo-overlapping-windings branch September 5, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants